package com.aos.erp.schools.util;

/**
 * @program: erp
 * @description: 按一定规则生成code
 * @author: tanzhiyu
 * @create: 2018-11-01 20:07
 **/
public class CodeUtil {
    /**
     * 生成规则部门编号:部门类型+五位编号（从1开始，不够前补0）
     *
     * @param type 部门类型
     * @param no   最新部门编号
     * @return
     */
    public static String getNewEquipmentNo(String type, String no) {
        String newEquipmentNo = "00001";

        if (no != null && !no.isEmpty()) {
            int newEquipment = Integer.parseInt(no) + 1;
            newEquipmentNo = String.format("%05d", newEquipment);
        }

        return type+newEquipmentNo;
    }

    public static void main(String[] args) {
        String code="A001D00002";
        String newCode=code.substring(code.length()-5,code.length());
        System.out.println(newCode);
        String equipmentNo = CodeUtil.getNewEquipmentNo("C", newCode);
        System.out.println("生成部门编号：" + equipmentNo);

       // System.out.println(code.substring(0,code.length()-6)+equipmentNo);
    }
}
